package com.foton.lotterydomain.rule.service.logic;

import com.foton.lotterycommon.common.Constants;
import com.foton.lotterydomain.rule.model.req.DecisionMatterReq;
import com.foton.lotterydomain.rule.model.vo.TreeNodeLineVO;

import java.util.List;

/**
 * @Author RenPu
 * @Date 2024/1/4 17:32
 * @Version 1.0
 * @Description: 规则逻辑 基础抽象类
 **/
public abstract class BaseLogic implements LogicFilter {


    @Override
    public Long filter(String matterValue, List<TreeNodeLineVO> treeNodeLineInfoList) {

        for (TreeNodeLineVO treeNodeLineVO : treeNodeLineInfoList) {
            if(decisionLogic(matterValue,treeNodeLineVO)){
              return treeNodeLineVO.getNodeIdTo();
            }
        }
        //设置默认值
        return Constants.Global.TREE_NULL_NODE;
    }


    /**
     * 根据获取的结果值，规则限制类型值（RuleLimitType）进行比较返回boolean值
     * @param matterValue
     * @param treeNodeLineVO
     * @return
     */
    private boolean decisionLogic(String matterValue, TreeNodeLineVO treeNodeLineVO){

        switch (treeNodeLineVO.getRuleLimitType()){
            case Constants.RuleLimitType.EQUAL:
                return matterValue.equals(treeNodeLineVO.getRuleLimitValue());
            case Constants.RuleLimitType.GT:
                return Double.parseDouble(matterValue) > Double.parseDouble(treeNodeLineVO.getRuleLimitValue());
            case Constants.RuleLimitType.LT:
                return Double.parseDouble(matterValue) < Double.parseDouble(treeNodeLineVO.getRuleLimitValue());
            case Constants.RuleLimitType.GE:
                return Double.parseDouble(matterValue) >= Double.parseDouble(treeNodeLineVO.getRuleLimitValue());
            case Constants.RuleLimitType.LE:
                return Double.parseDouble(matterValue) <= Double.parseDouble(treeNodeLineVO.getRuleLimitValue());

            default:
                return false;

        }


    }

    @Override
    public abstract String matterValue(DecisionMatterReq decisionMatter);



}
